
var app = getApp();
var api = require('../../utils/util.js');
Page({
  data: {
    cash_list: [],
    show_no_data_tip: !1,
    withdrawWay:'',
    userId:''
  },
  /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function (options) {
    this.setData({
      userId: options.userId,
      balance: wx.getStorageSync("balance")
    })
    //获取手机高度
    this.setData({
      navH: app.globalData.navHeight
    })
    if (options.partnerUserId == undefined) {
      this.setData({
        partnerUserId: 0
      })
    } else {
      this.setData({
        partnerUserId: options.partnerUserId
      })
    }
    this.setData({
      type: options.type
    })
    var that = this;
    wx.request({
      url: app.globalData.url + "getParaById?paraId=recharge_flag",
      method: "GET",
      data: {
      },
      success: function (res) {
        if (res.data.result == 1) {
          that.setData({
            recharge: res.data.data.value
          })
        } 
      }
    });
  },
  /**
   * 页面分享
   */
  onShareAppMessage: function () {
    var that = this;
    return {
      title: that.data.title,
      desc: '分享页面的内容',
      imageUrl: "http://file.jwsxmall.com/shareImg.jpg",
      path: '/pages/myPage/myPage?partnerUserId=' + wx.getStorageSync("userId") + '&type=0', // 路径，传递参数到指定页面
   
    }
  },
  onShow:function(){
    var that = this;
    that.setData({
      token: wx.getStorageSync("token")
    });
    api.authorization(0, that.data.partnerUserId);
    var userid = wx.getStorageSync("userId");
    var avatar = wx.getStorageSync("avatar");
    
    wx.request({
      url: app.globalData.url + "getMyWallet",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
        userId: that.data.userId,
        token: that.data.token
      },
      method: "POST",
      success: function (res) {
        var data = res.data;
        if (data.result === 1) {
          console.info(res.data.token);
          if (res.data.token != "" && res.data.token != undefined) {
            wx.setStorageSync("token", res.data.token)
          }
          that.setData({
            nickName: data.data.nickName,
            balance: data.data.balance,
            withdrawWay: data.data.withdrawWay,
            aveWithdrawal: data.data.aveWithdrawal,
            aveWithdrawal: data.data.aveWithdrawal,
            withdrawLimitPrice: data.data.withdrawLimitPrice,
            pointsDiffPoints: data.data.pointsDiffPoints,
            noDiffPoints: data.data.noDiffPoints,
            noAveWithdrawal: data.data.noAveWithdrawal,
            lastMonthWithdrawal: data.data.lastMonthWithdrawal,
            currentMonthWithdrawal: data.data.currentMonthWithdrawal,
            avatar: avatar,
            wechatUnoinId : wx.getStorageSync("wechatUnoinId")
          })
        }
        if (res.data.result == 9) {
          wx.reLaunch({
            url: '/pages/zcuslist/index',
          })
          return false;
        }
      }
    });
  },
  //页面加载
  onReady: function () {
    // var userid = wx.getStorageSync("userId");
    // var wechatOpenid = wx.getStorageSync("wechatOpenid");
    // var avatar = wx.getStorageSync("avatar");
    // var that = this;
    // wx.request({
    //   url: app.globalData.url + "getMyWallet",
    //   header: {
    //     "content-type": "application/x-www-form-urlencoded"
    //   },
    //   data: {
    //     userId: that.data.userId,
    //   },
    //   method: "POST",
    //   success: function (res) {
    //     var data = res.data;
    //     if (data.result === 1) {
    //       console.info(data.data.nickName);
    //       that.setData({
    //         nickName: data.data.nickName,
    //         balance: data.data.balance,
    //         withdrawWay: data.data.withdrawWay,
    //         aveWithdrawal: data.data.aveWithdrawal,
    //         aveWithdrawal: data.data.aveWithdrawal,
    //         noSettlement: data.data.noSettlement,
    //         withdrawLimitPrice: data.data.withdrawLimitPrice,
    //         pointsDiffPoints: data.data.pointsDiffPoints,
    //         pointsNoSettlement: data.data.pointsNoSettlement,
    //         noDiffPoints: data.data.noDiffPoints,
    //         noAveWithdrawal: data.data.noAveWithdrawal,
    //         wechatOpenid: wechatOpenid,
    //         avatar: avatar
    //       })
    //       console.info(wechatOpenid);
    //     } else {
    //       var show = data.errmsg;
    //       console.log(show)
    //       wx.showToast({
    //         icon: "none"
    //       })
    //     }
    //   }
    // });
  },
  onPullDownRefresh: function () { },
  onReachBottom: function () {
    var s = this;
    is_loading || is_no_more || (is_loading = !0, getApp().request({
      url: getApp().api.share.cash_detail,
      data: {
        status: s.data.status,
        page: p
      },
      success: function (t) {
        if (0 == t.code) {
          var a = s.data.cash_list.concat(t.data.list);
          s.setData({
            cash_list: a
          }), 0 == t.data.list.length && (is_no_more = !0);
        }
        p++;
      },
      complete: function () {
        is_loading = !1;
      }
    }));
  },
  //跳转余额明细
  toWithdrawal: function (res) {
    var that = this;
    console.info(that.data.userId);
    wx.navigateTo({
      url: '/pages/balanceDetail/balanceDetail?userId='+that.data.userId,
    })
  },
  //跳转充值页面
  upgrade: function (res) {
    var that = this;
    if ( that.data.recharge == 1){
      wx.showToast({
        title: '功能暂未开放',  // 标题
        icon: 'none',   // 图标类型，默认success
        duration: 1500   // 提示窗停留时间，默认1500ms
      })
      return false;
    }
    wx.navigateTo({
      url: '/pages/recharge/recharge',
    })
  }, 
  //跳转提现页面
  
  withdrawal: function(ele) {
    var that = this;
    console.info(111);
    wx.navigateTo({
      url: '/pages/withdraw/withdraw?userId=' + that.data.userId+'&withdrawWay=' + that.data.withdrawWay + "&withdrawLimitPrice=" + that.data.withdrawLimitPrice,
    })
  },


  navBack: function () {
    wx.navigateBack({

    })
  },
  withdrawal:function(){
    wx.navigateTo({
      url: '/pages/withdrawal/withdrawal',
    })
  },
});